<!-- 咨询记录 -->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="关键字" prop="searchValue">
        <el-input
          v-model="queryParams.searchValue"
          placeholder="请输入关键字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="咨询类型" prop="callType">
        <el-select v-model="queryParams.callType" placeholder="请选择咨询类型">
            <el-option
              v-for="dict in dict.type.calltype"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value">
            </el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="咨询方式" prop="callMethod">
        <el-select v-model="queryParams.callMethod" placeholder="请选择咨询方式">
            <el-option
              v-for="dict in dict.type.call_method"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value">
            </el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="开始时间" prop="callTime">
        <el-date-picker
              v-model="callTime"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期">
            </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb-8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:order:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="咨询订单" align="center" prop="meetingId" />
      <el-table-column label="咨询类型" align="center" prop="callType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.calltype" :value="scope.row.callType"/>
        </template>
      </el-table-column>
      <el-table-column label="咨询方式" align="center" prop="callMethod">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.call_method" :value="scope.row.callMethod"/>
        </template>
      </el-table-column>
      <el-table-column label="开始时间" align="center" prop="callTimestart" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.callTimestart) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束时间" align="center" prop="callTimeend" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.callTimeend) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="关联订单" align="center" prop="orderNo" />
      <el-table-column label="操作" align="center" :show-overflow-tooltip="true">
        <!-- <template slot-scope="scope">
          <router-link :to="'/system/dict-data/index/' + scope.row.id" class="link-type">
            <span>{{ scope.row.meetingId }}</span>
          </router-link>
        </template> -->
        <template slot-scope="scope">
          <router-link :to="'/order/consultdetails/index/' + scope.row.id" class="link-type">
            <span>咨询详情</span>
          </router-link>&nbsp;&nbsp;
          <router-link :to="'/order/consultdetails/index/' + scope.row.id" class="link-type">
            <span>结算详情</span>
          </router-link>
        </template>
      </el-table-column>

     <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-info"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:order:edit']"
          >咨询详情</el-button>
        </template>


        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-info"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:order:edit']"
          >结算详情</el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

     <el-dialog :title="vodsTitle" :visible.sync="vodsOpen" width="1000px" append-to-body>
       <el-table :data="vodsList" >
         <el-table-column label="id" align="center" prop="vodId" />
         <el-table-column label="视频名称" align="center" prop="displayName" />
         <el-table-column label="开始时间" align="center" prop="startTime" />
         <el-table-column label="结束时间" align="center" prop="endTime" />
         <el-table-column label="文件大小" align="center" prop="fileSize" />
         <el-table-column label="设备号" align="center" prop="nemoNumber" />
         <el-table-column label="下载链接" align="center" prop="transcriptionTxtFileUrl" />
       </el-table>

       <pagination
         v-show="vodsTotal>0"
         :total="vodsTotal"
         :page.sync="vodsQueryParams.pageNum"
         :limit.sync="vodsQueryParams.pageSize"
         @pagination="getVodsList"
       />

       <div slot="footer" class="dialog-footer">
         <el-button @click="vodsCancel">关闭</el-button>
       </div>
     </el-dialog>

    <!-- 添加或修改会议对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules"  :show-message="false" label-width="80px">
        <el-form-item label="云会议号" prop="meetingRoomNumber">
          <el-input v-model="form.meetingRoomNumber" placeholder="请输入云会议号" />
        </el-form-item>
        <el-form-item label="房间号" prop="meetingId">
          <el-input v-model="form.meetingId" placeholder="请输入房间号" />
        </el-form-item>
        <el-form-item label="客户端id" prop="clientId">
          <el-input v-model="form.clientId" placeholder="请输入客户端id" />
        </el-form-item>
        <el-form-item label="房间标题" prop="title">
          <el-input v-model="form.title" placeholder="请输入房间标题" />
        </el-form-item>
        <el-form-item label="顾客名字" prop="username">
          <el-input v-model="form.username" placeholder="请输入顾客名字" />
        </el-form-item>
        <el-form-item label="顾客手机号" prop="userphone">
          <el-input v-model="form.userphone" placeholder="请输入顾客手机号" />
        </el-form-item>
        <el-form-item label="专家编号" prop="expertId">
          <el-input v-model="form.expertId" placeholder="请输入专家编号" />
        </el-form-item>
        <el-form-item label="专家名称" prop="experName">
          <el-input v-model="form.experName" placeholder="请输入专家名称" />
        </el-form-item>
        <el-form-item label="通话开始时间" prop="callTimestart">
          <el-date-picker clearable
            v-model="form.callTimestart"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择通话开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="通话结束时间" prop="callTimeend">
          <el-date-picker clearable
            v-model="form.callTimeend"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择通话结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="总费用(实际)" prop="cost">
          <el-input v-model="form.cost" placeholder="请输入总费用(实际)" />
        </el-form-item>
        <el-form-item label="用户费用" prop="costUser">
          <el-input v-model="form.costUser" placeholder="请输入用户费用" />
        </el-form-item>
        <el-form-item label="专家发起人费用" prop="costExp">
          <el-input v-model="form.costExp" placeholder="请输入专家发起人费用" />
        </el-form-item>
        <el-form-item label="其他专家费用" prop="costToexp">
          <el-input v-model="form.costToexp" placeholder="请输入其他专家费用" />
        </el-form-item>
        <el-form-item label="渠道费用" prop="costChannel">
          <el-input v-model="form.costChannel" placeholder="请输入渠道费用" />
        </el-form-item>
        <el-form-item label="平台费用" prop="costPlatform">
          <el-input v-model="form.costPlatform" placeholder="请输入平台费用" />
        </el-form-item>
        <el-form-item label="邀请码" prop="invitation">
          <el-input v-model="form.invitation" placeholder="请输入邀请码" />
        </el-form-item>
        <el-form-item label="咨询方式" prop="callMethod">
          <el-input v-model="form.callMethod" placeholder="请输入咨询方式" />
        </el-form-item>
        <el-form-item label="邀请嘉宾" prop="inviteGuests">
          <el-input v-model="form.inviteGuests" placeholder="请输入邀请嘉宾" />
        </el-form-item>
        <el-form-item label="咨询标准" prop="consultingStandards">
          <el-input v-model="form.consultingStandards" placeholder="请输入咨询标准" />
        </el-form-item>
        <el-form-item label="总费用(原价)" prop="costOriginal">
          <el-input v-model="form.costOriginal" placeholder="请输入总费用(原价)" />
        </el-form-item>
        <el-form-item label="发起单位费用" prop="costCom">
          <el-input v-model="form.costCom" placeholder="请输入发起单位费用" />
        </el-form-item>
        <el-form-item label="咨询渠道费用" prop="costTochannel">
          <el-input v-model="form.costTochannel" placeholder="请输入咨询渠道费用" />
        </el-form-item>
        <el-form-item label="咨询单位费用" prop="costTocom">
          <el-input v-model="form.costTocom" placeholder="请输入咨询单位费用" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder,vods } from "@/api/order/order";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "Record",
  dicts: ['calltype','call_method','order_status','consulting_standards'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      callTime:"",
      // 总条数
      total: 0,
      vodsTotal:0,
      // 会议表格数据
      orderList: [],
      vodsList:[],
      // 弹出层标题
      title: "",
      vodsTitle:"视频列表",
      // 是否显示弹出层
      open: false,
      vodsOpen:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        callTimeStart:null,
        callTimeEnd:null,
        searchValue: null,
        callType: null,
        callMethod: null,
        status: null,
        billStatus: null,
        userphone: null,
        expertId: null,
        experName: null,
        callTimestart: null,
        callTimeend: null,
        cost: null,
        costUser: null,
        costExp: null,
        costToexp: null,
        costChannel: null,
        costPlatform: null,
        status: null,
        invitation: null,
        callType: null,
        callMethod: null,
        inviteGuests: null,
        consultingStandards: null,
        costOriginal: null,
        costCom: null,
        costTochannel: null,
        costTocom: null
      },
      vodsQueryParams:{
        pageNum: 0,
        pageSize: 10,
        meetingRoomNumber:null,
        meetingId:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询会议列表 */
    getList() {
      if(this.callTime.length != '0'){
        this.queryParams.callTimeStart = this.callTime[0]
        this.queryParams.callTimeEnd = this.callTime[1]
      }
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询会议列表 */
    getVodsList() {
      vods(this.vodsQueryParams).then(response => {
        this.vodsList = response.data.list;
        this.vodsTotal = response.data.rowsTotal;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮
    vodsCancel() {
      this.vodsOpen = false;

    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        meetingRoomNumber: null,
        meetingId: null,
        clientId: null,
        title: null,
        username: null,
        userphone: null,
        expertId: null,
        experName: null,
        callTimestart: null,
        callTimeend: null,
        cost: null,
        costUser: null,
        costExp: null,
        costToexp: null,
        costChannel: null,
        costPlatform: null,
        status: "0",
        invitation: null,
        callType: null,
        createTime: null,
        updateTime: null,
        callMethod: null,
        inviteGuests: null,
        consultingStandards: null,
        costOriginal: null,
        costCom: null,
        costTochannel: null,
        costTocom: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加会议";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrder(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改会议";
      });
    },
    /** 修改按钮操作 */
    handleUpdateVods(row) {
      this.vodsOpen = true;
      this.vodsQueryParams.meetingRoomNumber=row.meetingRoomNumber;
      this.vodsQueryParams.meetingId=row.meetingId;
      this.getVodsList();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除会议编号为"' + ids + '"的数据项？').then(function() {
        return delOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('order/order/export', {
        ...this.queryParams
      }, `订单_${this.parseTime(new Date(),'{y}-{m}-{d}')}.xlsx`)
    }
  }
};
</script>
